package com.suixinsanren.design.iterator.demo03;

import java.awt.*;

public class Waitress {

    private DinerMenu dinerMenu;
    private PancakeHouseMenu pancakeHouseMenu;

    public Waitress(DinerMenu dinerMenu, PancakeHouseMenu pancakeHouseMenu) {
        this.dinerMenu = dinerMenu;
        this.pancakeHouseMenu = pancakeHouseMenu;
    }

    public void printMenu() {
        Iterator<MenuItem> dinerMenIterator = dinerMenu.iterator();
        Iterator<MenuItem> pancakeHouseIterator = pancakeHouseMenu.iterator();
        printMenu(dinerMenIterator);
        System.out.println("-----------");
        printMenu(pancakeHouseIterator);

    }

    public void printMenu(Iterator<MenuItem> iterator) {
        while (iterator.hasNext()) {
            MenuItem item = iterator.next();
            System.out.println(item.getName() + item.getDescription() + item.getPrice());
        }
    }

    public void removeByPrice(Iterator<MenuItem> iterator, double price) {
        while (iterator.hasNext()) {
            if (iterator.next().getPrice() > price) {
                iterator.remove();
            }
        }
    }

}
